package com.server.service.impl;

import java.text.ParseException;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.server.common.mockData.ReservoirTemperatureMockData;
import com.server.common.mockData.WaterAsMockData;
import com.server.common.mockData.WaterBod5MockData;
import com.server.common.mockData.WaterC2n2MockData;
import com.server.common.mockData.WaterC6h5ohMockData;
import com.server.common.mockData.WaterCdMockData;
import com.server.common.mockData.WaterCodMockData;
import com.server.common.mockData.WaterColiGroupMockData;
import com.server.common.mockData.WaterConductivityMockData;
import com.server.common.mockData.WaterCrMockData;
import com.server.common.mockData.WaterCuMockData;
import com.server.common.mockData.WaterDissolvedOxygenMockData;
import com.server.common.mockData.WaterEntireNMockData;
import com.server.common.mockData.WaterEntirePMockData;
import com.server.common.mockData.WaterFMockData;
import com.server.common.mockData.WaterHgMockData;
import com.server.common.mockData.WaterLasMockData;
import com.server.common.mockData.WaterMno4MockData;
import com.server.common.mockData.WaterNh3nMockData;
import com.server.common.mockData.WaterPbMockData;
import com.server.common.mockData.WaterPetroleumMockData;
import com.server.common.mockData.WaterPhMockData;
import com.server.common.mockData.WaterSMockData;
import com.server.common.mockData.WaterSeMockData;
import com.server.common.mockData.WaterTemperatureMockData;
import com.server.common.mockData.WaterZnMockData;
import com.server.entity.DeviceInfo;
import com.server.entity.ReservoirTemperature;
import com.server.entity.WaterAs;
import com.server.entity.WaterBod5;
import com.server.entity.WaterC2n2;
import com.server.entity.WaterC6h5oh;
import com.server.entity.WaterCd;
import com.server.entity.WaterCod;
import com.server.entity.WaterColiGroup;
import com.server.entity.WaterConductivity;
import com.server.entity.WaterCr;
import com.server.entity.WaterCu;
import com.server.entity.WaterDissolvedOxygen;
import com.server.entity.WaterEntireN;
import com.server.entity.WaterEntireP;
import com.server.entity.WaterF;
import com.server.entity.WaterHg;
import com.server.entity.WaterLas;
import com.server.entity.WaterMno4;
import com.server.entity.WaterNh3n;
import com.server.entity.WaterPb;
import com.server.entity.WaterPetroleum;
import com.server.entity.WaterPh;
import com.server.entity.WaterS;
import com.server.entity.WaterSe;
import com.server.entity.WaterTemperature;
import com.server.entity.WaterZn;
import com.server.mapper.DeviceInfoMapper;
import com.server.mapper.ReservoirTemperatureMapper;
import com.server.mapper.WaterAsMapper;
import com.server.mapper.WaterBod5Mapper;
import com.server.mapper.WaterC2n2Mapper;
import com.server.mapper.WaterC6h5ohMapper;
import com.server.mapper.WaterCdMapper;
import com.server.mapper.WaterCodMapper;
import com.server.mapper.WaterColiGroupMapper;
import com.server.mapper.WaterConductivityMapper;
import com.server.mapper.WaterCrMapper;
import com.server.mapper.WaterCuMapper;
import com.server.mapper.WaterDissolvedOxygenMapper;
import com.server.mapper.WaterEntireNMapper;
import com.server.mapper.WaterEntirePMapper;
import com.server.mapper.WaterFMapper;
import com.server.mapper.WaterHgMapper;
import com.server.mapper.WaterLasMapper;
import com.server.mapper.WaterMno4Mapper;
import com.server.mapper.WaterNh3nMapper;
import com.server.mapper.WaterPbMapper;
import com.server.mapper.WaterPetroleumMapper;
import com.server.mapper.WaterPhMapper;
import com.server.mapper.WaterSMapper;
import com.server.mapper.WaterSeMapper;
import com.server.mapper.WaterTemperatureMapper;
import com.server.mapper.WaterZnMapper;
import com.server.service.AutoService;
import com.server.utils.GlobalUtils;

@Service
@EnableAsync
public class AutoServiceImpl implements AutoService {

    @Autowired
    DeviceInfoMapper deviceInfoMapper;
    @Autowired
    ReservoirTemperatureMapper reservoirTemperatureMapper;

    @Transactional
    public void updateReservoirTemperature() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<ReservoirTemperature> qw;
            ReservoirTemperature rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "reservoir_temperature").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<ReservoirTemperature>();
                qw.eq("time", randomTime);
                rt = reservoirTemperatureMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) ReservoirTemperatureMockData.Map.get("range");
                    int decimal = ReservoirTemperatureMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new ReservoirTemperature();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setReservoirTemperature(newData);
                    reservoirTemperatureMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterAsMapper waterAsMapper;

    @Transactional
    public void updateWaterAs() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterAs> qw;
            WaterAs rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_as").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterAs>();
                qw.eq("time", randomTime);
                rt = waterAsMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterAsMockData.Map.get("range");
                    int decimal = WaterAsMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterAs();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setArsenic(newData);
                    waterAsMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterBod5Mapper waterBod5Mapper;

    @Transactional
    public void updateWaterBod5() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterBod5> qw;
            WaterBod5 rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_bod5").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterBod5>();
                qw.eq("time", randomTime);
                rt = waterBod5Mapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterBod5MockData.Map.get("range");
                    int decimal = WaterBod5MockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterBod5();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setBod5(newData);
                    waterBod5Mapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterC2n2Mapper waterC2n2Mapper;

    @Transactional
    public void updateWaterC2n2() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterC2n2> qw;
            WaterC2n2 rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_c2n2").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterC2n2>();
                qw.eq("time", randomTime);
                rt = waterC2n2Mapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterC2n2MockData.Map.get("range");
                    int decimal = WaterC2n2MockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterC2n2();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setC2n2(newData);
                    waterC2n2Mapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterC6h5ohMapper waterC6h5ohMapper;

    @Transactional
    public void updateWaterC6h5oh() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterC6h5oh> qw;
            WaterC6h5oh rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_c6h5oh").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterC6h5oh>();
                qw.eq("time", randomTime);
                rt = waterC6h5ohMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterC6h5ohMockData.Map.get("range");
                    int decimal = WaterC6h5ohMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterC6h5oh();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setC6h5oh(newData);
                    waterC6h5ohMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterCdMapper waterCdMapper;

    @Transactional
    public void updateWaterCd() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterCd> qw;
            WaterCd rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_cd").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterCd>();
                qw.eq("time", randomTime);
                rt = waterCdMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterCdMockData.Map.get("range");
                    int decimal = WaterCdMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterCd();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setCd(newData);
                    waterCdMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterCodMapper waterCodMapper;

    @Transactional
    public void updateWaterCod() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterCod> qw;
            WaterCod rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_cod").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterCod>();
                qw.eq("time", randomTime);
                rt = waterCodMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterCodMockData.Map.get("range");
                    int decimal = WaterCodMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterCod();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setCod(newData);
                    waterCodMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterColiGroupMapper waterColiGroupMapper;

    @Transactional
    public void updateWaterColiGroup() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterColiGroup> qw;
            WaterColiGroup rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_coli_group").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterColiGroup>();
                qw.eq("time", randomTime);
                rt = waterColiGroupMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterColiGroupMockData.Map.get("range");
                    int decimal = WaterColiGroupMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterColiGroup();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setColiGroup(newData);
                    waterColiGroupMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterConductivityMapper waterConductivityMapper;

    @Transactional
    public void updateWaterConductivity() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterConductivity> qw;
            WaterConductivity rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_conductivity").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterConductivity>();
                qw.eq("time", randomTime);
                rt = waterConductivityMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterConductivityMockData.Map.get("range");
                    int decimal = WaterConductivityMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterConductivity();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setConductivity(newData);
                    waterConductivityMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterCrMapper waterCrMapper;

    @Transactional
    public void updateWaterCr() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterCr> qw;
            WaterCr rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_cr").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterCr>();
                qw.eq("time", randomTime);
                rt = waterCrMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterCrMockData.Map.get("range");
                    int decimal = WaterCrMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterCr();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setCr(newData);
                    waterCrMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterCuMapper waterCuMapper;

    @Transactional
    public void updateWaterCu() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterCu> qw;
            WaterCu rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_cu").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterCu>();
                qw.eq("time", randomTime);
                rt = waterCuMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterCuMockData.Map.get("range");
                    int decimal = WaterCuMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterCu();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setCu(newData);
                    waterCuMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterDissolvedOxygenMapper waterDissolvedOxygenMapper;

    @Transactional
    public void updateWaterDissolvedOxygen() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterDissolvedOxygen> qw;
            WaterDissolvedOxygen rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_dissolved_oxygen").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterDissolvedOxygen>();
                qw.eq("time", randomTime);
                rt = waterDissolvedOxygenMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterDissolvedOxygenMockData.Map.get("range");
                    int decimal = WaterDissolvedOxygenMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterDissolvedOxygen();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setDissolvedOxygen(newData);
                    waterDissolvedOxygenMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterEntireNMapper waterEntireNMapper;

    @Transactional
    public void updateWaterEntireN() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterEntireN> qw;
            WaterEntireN rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_entire_n").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterEntireN>();
                qw.eq("time", randomTime);
                rt = waterEntireNMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterEntireNMockData.Map.get("range");
                    int decimal = WaterEntireNMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterEntireN();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setEntireN(newData);
                    waterEntireNMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterEntirePMapper waterEntirePMapper;

    @Transactional
    public void updateWaterEntireP() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterEntireP> qw;
            WaterEntireP rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_entire_p").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterEntireP>();
                qw.eq("time", randomTime);
                rt = waterEntirePMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterEntirePMockData.Map.get("range");
                    int decimal = WaterEntirePMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterEntireP();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setEntireP(newData);
                    waterEntirePMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterFMapper waterFMapper;

    @Transactional
    public void updateWaterF() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterF> qw;
            WaterF rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_f").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterF>();
                qw.eq("time", randomTime);
                rt = waterFMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterFMockData.Map.get("range");
                    int decimal = WaterFMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterF();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setF(newData);
                    waterFMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterHgMapper waterHgMapper;

    @Transactional
    public void updateWaterHg() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterHg> qw;
            WaterHg rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_hg").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterHg>();
                qw.eq("time", randomTime);
                rt = waterHgMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterHgMockData.Map.get("range");
                    int decimal = WaterHgMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterHg();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setHg(newData);
                    waterHgMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterLasMapper waterLasMapper;

    @Transactional
    public void updateWaterLas() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterLas> qw;
            WaterLas rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_las").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterLas>();
                qw.eq("time", randomTime);
                rt = waterLasMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterLasMockData.Map.get("range");
                    int decimal = WaterLasMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterLas();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setLas(newData);
                    waterLasMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterMno4Mapper waterMno4Mapper;

    @Transactional
    public void updateWaterMno4() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterMno4> qw;
            WaterMno4 rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_mno4").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterMno4>();
                qw.eq("time", randomTime);
                rt = waterMno4Mapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterMno4MockData.Map.get("range");
                    int decimal = WaterMno4MockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterMno4();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setMno4(newData);
                    waterMno4Mapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterNh3nMapper waterNh3nMapper;

    @Transactional
    public void updateWaterNh3n() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterNh3n> qw;
            WaterNh3n rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_nh3n").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterNh3n>();
                qw.eq("time", randomTime);
                rt = waterNh3nMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterNh3nMockData.Map.get("range");
                    int decimal = WaterNh3nMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterNh3n();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setNh3n(newData);
                    waterNh3nMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterPbMapper waterPbMapper;

    @Transactional
    public void updateWaterPb() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterPb> qw;
            WaterPb rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_pb").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterPb>();
                qw.eq("time", randomTime);
                rt = waterPbMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterPbMockData.Map.get("range");
                    int decimal = WaterPbMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterPb();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setPb(newData);
                    waterPbMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterPetroleumMapper waterPetroleumMapper;

    @Transactional
    public void updateWaterPetroleum() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterPetroleum> qw;
            WaterPetroleum rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_petroleum").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterPetroleum>();
                qw.eq("time", randomTime);
                rt = waterPetroleumMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterPetroleumMockData.Map.get("range");
                    int decimal = WaterPetroleumMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterPetroleum();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setPetroleum(newData);
                    waterPetroleumMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterPhMapper waterPhMapper;

    @Transactional
    public void updateWaterPh() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterPh> qw;
            WaterPh rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_ph").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterPh>();
                qw.eq("time", randomTime);
                rt = waterPhMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterPhMockData.Map.get("range");
                    int decimal = WaterPhMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterPh();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setPh(newData);
                    waterPhMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterSeMapper waterSeMapper;

    @Transactional
    public void updateWaterSe() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterSe> qw;
            WaterSe rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_se").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterSe>();
                qw.eq("time", randomTime);
                rt = waterSeMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterSeMockData.Map.get("range");
                    int decimal = WaterSeMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterSe();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setSe(newData);
                    waterSeMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterSMapper waterSMapper;

    @Transactional
    public void updateWaterS() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterS> qw;
            WaterS rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_s").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterS>();
                qw.eq("time", randomTime);
                rt = waterSMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterSMockData.Map.get("range");
                    int decimal = WaterSMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterS();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setS(newData);
                    waterSMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterTemperatureMapper waterTemperatureMapper;

    @Transactional
    public void updateWaterTemperature() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterTemperature> qw;
            WaterTemperature rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_temperature").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterTemperature>();
                qw.eq("time", randomTime);
                rt = waterTemperatureMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterTemperatureMockData.Map.get("range");
                    int decimal = WaterTemperatureMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterTemperature();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setWaterTemperature(newData);
                    waterTemperatureMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }

    @Autowired
    WaterZnMapper waterZnMapper;

    @Transactional
    public void updateWaterZn() {
        try {
            // 获取当前时间
            //Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime().substring(0,13) + ":00:00");
            Date currentTime = GlobalUtils.transformStringToDate(GlobalUtils.getCurrentTime());
            currentTime = GlobalUtils.aroundDateToFiveMinute(currentTime);
            //获取随机日期
            Date randomTime = GlobalUtils.randomDate("2023-01-01 00:00:00", "2024-07-21 00:00:00");
            randomTime = GlobalUtils.aroundDateToFiveMinute(randomTime);
            // 遍历每个设备
            QueryWrapper<WaterZn> qw;
            WaterZn rt;
            List<DeviceInfo> deviceList;
            Double newData = null;
            //获取随机合法deviceList
            QueryWrapper<DeviceInfo> deviceWrapper = new QueryWrapper<>();
            deviceWrapper.eq("functions", "water_zn").orderByAsc("stcd");
            deviceList = deviceInfoMapper.selectList(deviceWrapper);
            for (DeviceInfo di : deviceList) {
                int id = di.getId();
                Integer status = di.getStatus();
                // 查询表中是否存在设备的小时记录信息
                qw = new QueryWrapper<WaterZn>();
                qw.eq("time", randomTime);
                rt = waterZnMapper.selectOne(qw);
                // 如果当前数据不存在，则进行新增
                if (rt == null) {
                    // 获取测试模拟映射数据
                    Map<String, Double> MaxMinMap = (Map<String, Double>) WaterZnMockData.Map.get("range");
                    int decimal = WaterZnMockData.Decimal;
                    // 如果设备不正常或者模拟数据为极值为空，则不获取随机值
                    if (status == 1 && MaxMinMap.get("max") != null && MaxMinMap.get("min") != null) {
                        newData = GlobalUtils.getRandomDataByRange(MaxMinMap.get("min"), MaxMinMap.get("max"), decimal);
                    }
                    // 插入模拟数据
                    // System.out.println(id+","+currentTime+","+newData);
                    // 新增数据
                    rt = new WaterZn();
                    rt.setTime(currentTime);
                    rt.setDeviceId(id);
                    rt.setZn(newData);
                    waterZnMapper.insert(rt);
                }
            }
        } catch (ParseException e) {
            e.printStackTrace();
        }
    }
}
